cmake_minimum_required(VERSION 3.5)
project(Bitmap)

# 设置 Doxygen 相关参数
option(BUILD_DOCUMENTATION "Build the documentation" ON)
if(BUILD_DOCUMENTATION)
    find_package(Doxygen)
    if(DOXYGEN_FOUND)
        set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
        set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

        configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

        add_custom_target(docs
            COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
            COMMENT "Generating documentation with Doxygen"
            VERBATIM
        )

        install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html DESTINATION ${CMAKE_INSTALL_PREFIX}/doc)
    else()
        message(WARNING "Doxygen not found, unable to generate documentation")
    endif()
endif()  

set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/example/manderbrot.cpp)

# 设置 rpath 参数
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

if(APPLE)
    set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
elseif(UNIX)
    set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
endif()

add_library(bitmap SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/bitmap.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

add_executable(manderbrot ${SOURCES})
target_link_libraries(manderbrot bitmap)

install(TARGETS manderbrot DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS bitmap DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html DESTINATION ${CMAKE_INSTALL_PREFIX}/doc OPTIONAL)
